home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gcc_260.zip / gcc_260 / fixincludes < prev    next >
Text File  |  1994-06-30  |  56KB  |  1,787 lines

  1. #! /bin/sh
  2. # Install modified versions of certain ANSI-incompatible system header files
  3. # which are fixed to work correctly with ANSI C
  4. # and placed in a directory that GNU C will search.
  5.  
  6. # See README-fixinc for more information.
  7.  
  8. # Directory containing the original header files.
  9. # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
  10. INPUT=${2-${INPUT-/usr/include}}
  11.  
  12. # Directory in which to store the results.
  13. LIB=${1?"fixincludes: output directory not specified"}
  14.  
  15. # Define PWDCMD as a command to use to get the working dir
  16. # in the form that we want.
  17. PWDCMD=pwd
  18. case "`pwd`" in
  19. //*)
  20.     # On an Apollo, discard everything before `/usr'.
  21.     PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
  22.     ;;
  23. esac
  24.  
  25. # Original directory.
  26. ORIGDIR=`${PWDCMD}`
  27.  
  28. # Make sure it exists.
  29. if [ ! -d $LIB ]; then
  30.   mkdir $LIB || exit 1
  31. fi
  32.  
  33. # Make LIB absolute only if needed to avoid problems with the amd.
  34. case $LIB in
  35. /*)
  36.     ;;
  37. *)
  38.     cd $LIB; LIB=`${PWDCMD}`
  39.     ;;
  40. esac
  41.  
  42. # Fail if no arg to specify a directory for the output.
  43. if [ x$1 = x ]
  44. then echo fixincludes: no output directory specified
  45. exit 1
  46. fi
  47.  
  48. echo Building fixed headers in ${LIB}
  49.  
  50. # Determine whether this system has symbolic links.
  51. if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
  52.   rm -f $LIB/ShouldNotExist
  53.   LINKS=true
  54. elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
  55.   rm -f /tmp/ShouldNotExist
  56.   LINKS=true
  57. else
  58.   LINKS=false
  59. fi
  60.  
  61. echo Finding directories and links to directories
  62. cd ${INPUT}
  63. # Find all directories and all symlinks that point to directories.
  64. # Put the list in $files.
  65. # Each time we find a symlink, add it to newdirs
  66. # so that we do another find within the dir the link points to.
  67. # Note that $files may have duplicates in it;
  68. # later parts of this file are supposed to ignore them.
  69. dirs="."
  70. levels=2
  71. while [ -n "$dirs" ] && [ $levels -gt 0 ]
  72. do
  73.     levels=`expr $levels - 1`
  74.     newdirs=
  75.     for d in $dirs
  76.     do
  77.     echo " Searching $INPUT/$d"
  78.     if [ "$d" != . ]
  79.     then
  80.         d=$d/.
  81.     fi
  82.  
  83.     # Find all directories under $d, relative to $d, excluding $d itself.
  84.         files="$files `find $d -type d -print | \
  85.                sed -e '/\/\.$/d' -e '/^\.$/d'`"
  86.     # Find all links to directories.
  87.     # Using `-exec test -d' in find fails on some systems,
  88.     # and trying to run test via sh fails on others,
  89.     # so this is the simplest alternative left.
  90.     # First find all the links, then test each one.
  91.     theselinks=
  92.     $LINKS && \
  93.       theselinks=`find $d -type l -print`
  94.     for d1 in $theselinks --dummy--
  95.     do
  96.         # If the link points to a directory,
  97.         # add that dir to $newdirs
  98.         if [ -d $d1 ]
  99.         then
  100.         files="$files $d1"
  101.         if [ "`ls -ld $d1 | sed -n 's/.*-> //p'`" != "." ]
  102.         then
  103.             newdirs="$newdirs $d1"
  104.         fi
  105.         fi
  106.     done
  107.     done
  108.  
  109.     dirs="$newdirs"
  110. done
  111.  
  112. dirs=
  113. echo "All directories (including links to directories):"
  114. echo $files
  115.  
  116. for file in $files; do
  117.   rm -rf $LIB/$file
  118.   if [ ! -d $LIB/$file ]
  119.   then mkdir $LIB/$file
  120.   fi
  121. done
  122. mkdir $LIB/root
  123.  
  124. # treetops gets an alternating list
  125. # of old directories to copy
  126. # and the new directories to copy to.
  127. treetops="${INPUT} ${LIB}"
  128.  
  129. if $LINKS; then
  130.   echo 'Making symbolic directory links'
  131.   for file in $files; do
  132.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  133.     if [ "$dest" ]; then    
  134.       cwd=`${PWDCMD}`
  135.       # In case $dest is relative, get to $file's dir first.
  136.       cd ${INPUT}
  137.       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
  138.       # Check that the target directory exists.
  139.       # Redirections changed to avoid bug in sh on Ultrix.
  140.       (cd $dest) > /dev/null 2>&1
  141.       if [ $? = 0 ]; then
  142.     cd $dest
  143.     # X gets the dir that the link actually leads to.
  144.     x=`${PWDCMD}`
  145.     # If a link points to ., make a similar link to .
  146.     if [ $x = $INPUT ]; then
  147.       echo $file '->' . ': Making link'
  148.       rm -fr ${LIB}/$file > /dev/null 2>&1
  149.       ln -s . ${LIB}/$file > /dev/null 2>&1
  150.     # If link leads back into ${INPUT},
  151.     # make a similar link here.
  152.     elif expr $x : "${INPUT}/.*" > /dev/null; then
  153.       # Y gets the actual target dir name, relative to ${INPUT}.
  154.       y=`echo $x | sed -n "s&${INPUT}/&&p"`
  155.       # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
  156.       dots=`echo "$file" |
  157.         sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
  158.       echo $file '->' $dots$y ': Making link'
  159.       rm -fr ${LIB}/$file > /dev/null 2>&1
  160.       ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
  161.     else
  162.       # If the link is to a dir $target outside ${INPUT},
  163.       # repoint the link at ${INPUT}/root$target
  164.       # and process $target into ${INPUT}/root$target
  165.       # treat this directory as if it actually contained the files.
  166.       echo $file '->' root$x ': Making link'
  167.       if [ -d $LIB/root$x ]
  168.       then true
  169.       else
  170.         dirname=root$x/
  171.         dirmade=.
  172.         cd $LIB
  173.         while [ x$dirname != x ]; do
  174.           component=`echo $dirname | sed -e 's|/.*$||'`
  175.           mkdir $component >/dev/null 2>&1
  176.           cd $component
  177.           dirmade=$dirmade/$component
  178.           dirname=`echo $dirname | sed -e 's|[^/]*/||'`
  179.         done
  180.       fi
  181.       # Duplicate directory structure created in ${LIB}/$file in new
  182.       # root area.
  183.       for file2 in $files; do
  184.         case $file2 in
  185.           $file/./*)
  186.         dupdir=${LIB}/root$x/`echo $file2 | sed -n "s|^${file}/||p"`
  187.         echo "Duplicating ${file}'s ${dupdir}"
  188.         if [ -d ${dupdir} ]
  189.         then true
  190.         else
  191.           mkdir ${dupdir}
  192.         fi
  193.         ;;
  194.           *)
  195.         ;;
  196.         esac
  197.           done
  198.       # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
  199.       dots=`echo "$file" |
  200.         sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
  201.       rm -fr ${LIB}/$file > /dev/null 2>&1
  202.       ln -s ${dots}root$x ${LIB}/$file > /dev/null 2>&1
  203.       treetops="$treetops $x ${LIB}/root$x"
  204.     fi
  205.       fi
  206.       cd $cwd
  207.     fi
  208.   done
  209. fi
  210.  
  211. required=
  212. set x $treetops
  213. shift
  214. while [ $# != 0 ]; do
  215.   # $1 is an old directory to copy, and $2 is the new directory to copy to.
  216.   cd ${INPUT}
  217.   cd $1
  218. # The same dir can appear more than once in treetops.
  219. # There's no need to scan it more than once.
  220.   if [ -f $2/DONE ]
  221.   then
  222.     files=
  223.   else
  224.     touch $2/DONE
  225.     echo Fixing directory $1 into $2
  226. # Check .h files which are symlinks as well as those which are files.
  227. # A link to a header file will not be processed by anything but this.
  228.     if $LINKS; then
  229.       files=`find . -name '*.h' \( -type f -o -type l \) -print`
  230.     else
  231.       files=`find . -name '*.h' -type f -print`
  232.     fi
  233.     echo Checking header files
  234.   fi
  235. # Note that BSD43_* are used on recent MIPS systems.
  236.   for file in $files; do
  237. # This call to egrep is essential, since checking a file with egrep
  238. # is much faster than actually trying to fix it.
  239. # It is also essential that most files *not* match!
  240. # Thus, matching every #endif is unacceptable.
  241. # But the argument to egrep must be kept small, or many versions of egrep
  242. # won't be able to handle it.
  243. #
  244. # We use the pattern [!-.0-~] instead of [^/     ] to match a noncomment
  245. # following #else or #endif because some buggy egreps think [^/] matches
  246. # newline, and they thus think `#else ' matches `#e[ndiflse]*[     ]+[^/     ]'.
  247. #
  248. # We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
  249. # following #if or #elif that is not surrounded by __.  The `a-ce-km-z'
  250. # in this pattern lacks `d' and `l'; this means we don't worry about
  251. # identifiers starting with `d' or `l'.  This is OK, since none of the
  252. # identifiers below start with `d' or `l'.  It also greatly improves
  253. # performance, since many files contain lines of the form `#if ... defined ...'
  254. # or `#if lint'.
  255.     if egrep '//|[     _]_IO|CTRL|^#define.NULL|^#e[nl][ds][ief]*[     ]+[!-.0-~]|^#[el]*if.*[^a-zA-Z0-9_][_a-ce-km-zA-Z][a-zA-Z0-9]' $file >/dev/null; then
  256.       if [ -r $file ]; then
  257.     cp $file $2/$file >/dev/null 2>&1    \
  258.     || echo "Can't copy $file"
  259.     chmod +w $2/$file
  260.     chmod a+r $2/$file
  261.     # Here is how the sed commands in braces work.
  262.     # (It doesn't work to put the comments inside the sed commands.)
  263.         # Surround each word with spaces, to simplify matching below.
  264.         # ANSIfy each pre-ANSI machine-dependent symbol
  265.         # by surrounding it with __ __.
  266.         # Remove the spaces that we inserted around each word.
  267.     sed -e '
  268.                    :loop
  269.       /\\$/            N
  270.       /\\$/            b loop
  271.       s%^\([     ]*#[     ]*else\)[     ]*/[^*].*%\1%
  272.       s%^\([     ]*#[     ]*else\)[     ]*[^/     ].*%\1%
  273.       s%^\([     ]*#[     ]*endif\)[     ]*/[^*].*%\1%
  274.       s%^\([     ]*#[     ]*endif\)[     ]*\*[^/].*%\1%
  275.       s%^\([     ]*#[     ]*endif\)[     ]*[^/*     ].*%\1%
  276.       /\/\/[^*]/            s|//\(.*\)$|/*\1*/|
  277.       /[     ]_IO[A-Z]*[     ]*(/    s/\(_IO[A-Z]*[     ]*(\)\(.\),/\1'\''\2'\'',/
  278.       /[     ]BSD43__IO[A-Z]*[     ]*(/    s/(\(.\),/('\''\1'\'',/
  279.       /#define._IO/            s/'\''\([cgxtf]\)'\''/\1/g
  280.       /#define.BSD43__IO/        s/'\''\([cgx]\)'\''/\1/g
  281.       /[^A-Z0-9_]CTRL[     ]*(/        s/\([^'\'']\))/'\''\1'\'')/
  282.       /[^A-Z0-9]_CTRL[     ]*(/        s/\([^'\'']\))/'\''\1'\'')/
  283.       /#define[     ]*[     ]CTRL/        s/'\''\([cgx]\)'\''/\1/g
  284.       /#define[     ]*[     ]_CTRL/        s/'\''\([cgx]\)'\''/\1/g
  285.       /#define.BSD43_CTRL/        s/'\''\([cgx]\)'\''/\1/g
  286.       /#[el]*if/{
  287.         s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
  288.  
  289.         s/ bsd4\([0-9]\) / __bsd4\1__ /g
  290.         s/ _*host_mips / __host_mips__ /g
  291.         s/ _*i386 / __i386__ /g
  292.         s/ M32 / __M32__ /g
  293.         s/ is68k / __is68k__ /g
  294.         s/ m68k / __m68k__ /g
  295.         s/ mc680\([0-9]\)0 / __mc680\10__ /g
  296.         s/ m88k / __m88k__ /g
  297.         s/ _*mips / __mips__ /g
  298.         s/ news\([0-9]*\) / __news\1__ /g
  299.         s/ ns32000 / __ns32000__ /g
  300.         s/ pdp11 / __pdp11__ /g
  301.         s/ pyr / __pyr__ /g
  302.         s/ sony_news / __sony_news__ /g
  303.         s/ sparc / __sparc__ /g
  304.         s/ sun\([a-z0-9]*\) / __sun\1__ /g
  305.         s/ tower\([_0-9]*\) / __tower\1__ /g
  306.         s/ u370 / __u370__ /g
  307.         s/ u3b\([0-9]*\) / __u3b\1__ /g
  308.         s/ unix / __unix__ /g
  309.         s/ vax / __vax__ /g
  310.         s/ _*MIPSE\([LB]\) / __MIPSE\1__ /g
  311.         s/ _*R\([34]\)000 / __R\1000__ /g
  312.         s/ _*SYSTYPE_\([A-Z0-9]*\) / __SYSTYPE_\1__ /g
  313.  
  314.         s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
  315.       }
  316.       /^#define.NULL[     ]/    i\
  317.         #undef NULL
  318.     ' $2/$file > $2/$file.
  319.     mv $2/$file. $2/$file
  320.     if cmp $file $2/$file >/dev/null 2>&1; then
  321.        rm $2/$file
  322.     else
  323.        echo Fixed $file
  324.        # Find any include directives that use "file".
  325.        for include in `egrep '^[     ]*#[     ]*include[     ]*"[^/]' $2/$file | sed -e 's/^[     ]*#[     ]*include[     ]*"\([^"]*\)".*$/\1/'`; do
  326.           dir=`echo $file | sed -e s'|/[^/]*$||'`
  327.           required="$required $1 $dir/$include $2/$dir/$include"
  328.        done
  329.     fi
  330.       fi
  331.     fi
  332.   done
  333.   shift; shift
  334. done
  335.  
  336. cd ${INPUT}
  337.  
  338. # Install the proper definition of the three standard types in header files
  339. # that they come from.
  340. for file in sys/types.h stdlib.h sys/stdtypes.h stddef.h memory.h unistd.h; do
  341.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  342.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  343.     chmod +w ${LIB}/$file 2>/dev/null
  344.     chmod a+r ${LIB}/$file 2>/dev/null
  345.   fi
  346.  
  347.   if [ -r ${LIB}/$file ]; then
  348.     echo Fixing size_t, ptrdiff_t and wchar_t in $file
  349.     sed \
  350.       -e '/typedef[     ][     ]*[a-z_][     a-z_]*[     ]size_t/i\
  351. #ifndef __SIZE_TYPE__\
  352. #define __SIZE_TYPE__ long unsigned int\
  353. #endif
  354. ' \
  355.       -e 's/typedef[     ][     ]*[a-z_][     a-z_]*[     ]size_t/typedef __SIZE_TYPE__ size_t/' \
  356.       -e '/typedef[     ][     ]*[a-z_][     a-z_]*[     ]ptrdiff_t/i\
  357. #ifndef __PTRDIFF_TYPE__\
  358. #define __PTRDIFF_TYPE__ long int\
  359. #endif
  360. ' \
  361.       -e 's/typedef[     ][     ]*[a-z_][     a-z_]*[     ]ptrdiff_t/typedef __PTRDIFF_TYPE__ ptrdiff_t/' \
  362.       -e '/typedef[     ][     ]*[a-z_][     a-z_]*[     ]wchar_t/i\
  363. #ifndef __WCHAR_TYPE__\
  364. #define __WCHAR_TYPE__ int\
  365. #endif
  366. ' \
  367.       -e 's/typedef[     ][     ]*[a-z_][     a-z_]*[     ]wchar_t/typedef __WCHAR_TYPE__ wchar_t/' \
  368.       ${LIB}/$file > ${LIB}/${file}.sed
  369.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  370.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  371.       rm ${LIB}/$file
  372.     fi
  373.   fi
  374. done
  375.  
  376. # Fix one other error in this file: a mismatched quote not inside a C comment.
  377. file=sundev/vuid_event.h
  378. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  379.   mkdir ${LIB}/sundev 2>/dev/null
  380.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  381.   chmod +w ${LIB}/$file 2>/dev/null
  382.   chmod a+r ${LIB}/$file 2>/dev/null
  383. fi
  384.  
  385. if [ -r ${LIB}/$file ]; then
  386.   echo Fixing $file comment
  387.   sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
  388.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  389.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  390.     rm ${LIB}/$file
  391.   fi
  392. fi
  393.  
  394. # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
  395. file=sunwindow/win_cursor.h
  396. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  397. #  mkdir ${LIB}/sunwindow 2>/dev/null
  398.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  399.   chmod +w ${LIB}/$file 2>/dev/null
  400. fi
  401. if [ -r ${LIB}/$file ]; then
  402.   echo Fixing $file
  403.   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
  404.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  405.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  406.     rm ${LIB}/$file
  407.   fi
  408. fi
  409. file=sunwindow/win_lock.h
  410. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  411. #  mkdir ${LIB}/sunwindow 2>/dev/null
  412.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  413.   chmod +w ${LIB}/$file 2>/dev/null
  414. fi
  415. if [ -r ${LIB}/$file ]; then
  416.   echo Fixing $file
  417.   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
  418.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  419.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  420.     rm ${LIB}/$file
  421.   fi
  422. fi
  423.  
  424. # Fix this Sun file to avoid interfering with stddef.h.
  425. file=sys/stdtypes.h
  426. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  427.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  428.   chmod +w ${LIB}/$file 2>/dev/null
  429.   chmod a+r ${LIB}/$file 2>/dev/null
  430. fi
  431.  
  432. if [ -r ${LIB}/$file ]; then
  433.   echo Fixing $file
  434. sed -e '/[     ]size_t.*;/i\
  435. #ifndef _GCC_SIZE_T\
  436. #define _GCC_SIZE_T
  437. ' \
  438.     -e '/[     ]size_t.*;/a\
  439. #endif
  440. ' \
  441.     -e '/[     ]ptrdiff_t.*;/i\
  442. #ifndef _GCC_PTRDIFF_T\
  443. #define _GCC_PTRDIFF_T
  444. ' \
  445.     -e '/[     ]ptrdiff_t.*;/a\
  446. #endif
  447. ' \
  448.     -e '/[     ]wchar_t.*;/i\
  449. #ifndef _GCC_WCHAR_T\
  450. #define _GCC_WCHAR_T
  451. ' \
  452.     -e '/[     ]wchar_t.*;/a\
  453. #endif
  454. ' ${LIB}/$file > ${LIB}/${file}.sed
  455.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  456.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  457.     rm ${LIB}/$file
  458.   fi
  459. fi
  460.  
  461. # Fix this ARM/RISCiX file to avoid interfering with the use of __wchar_t
  462. # in cc1plus.
  463. file=stdlib.h
  464. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  465.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  466.   chmod +w ${LIB}/$file 2>/dev/null
  467.   chmod a+r ${LIB}/$file 2>/dev/null
  468. fi
  469.  
  470. if [ -r ${LIB}/$file ]; then
  471.   echo Fixing $file
  472.   sed -e "s/\(#[     ]*ifndef[     ]*\)__wchar_t/\1_GCC_WCHAR_T/" \
  473.       -e "s/\(#[     ]*define[     ]*\)__wchar_t/\1_GCC_WCHAR_T/" \
  474.      ${LIB}/$file > ${LIB}/${file}.sed
  475.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  476.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  477.     rm ${LIB}/$file
  478.   fi
  479. fi
  480.  
  481. # Fix this file to avoid interfering with stddef.h, but don't mistakenly
  482. # match ssize_t present in AIX for the ps/2, or typedefs which use (but do not
  483. # set) size_t.
  484. file=sys/types.h
  485. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  486.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  487.   chmod +w ${LIB}/$file 2>/dev/null
  488.   chmod a+r ${LIB}/$file 2>/dev/null
  489. fi
  490.  
  491. if [ -r ${LIB}/$file ]; then
  492.   echo Fixing $file
  493. sed -e '/typedef[     ][     ]*[A-Za-z_][     A-Za-z_]*[     ]size_t/i\
  494. #ifndef _GCC_SIZE_T\
  495. #define _GCC_SIZE_T
  496. ' \
  497.     -e '/typedef[     ][     ]*[A-Za-z_][     A-Za-z_]*[     ]size_t/a\
  498. #endif
  499. ' ${LIB}/$file > ${LIB}/${file}.sed
  500.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  501.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  502.     rm ${LIB}/$file
  503.   fi
  504. fi
  505.  
  506. # Fix HP's use of ../machine/inline.h to refer to
  507. # /usr/include/machine/inline.h
  508. file=sys/spinlock.h
  509. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  510.   cp $file ${LIB}/$file
  511. fi
  512. if [ -r ${LIB}/$file ] ; then
  513.   echo Fixing $file
  514.   sed -e 's,"../machine/inline.h",<machine/inline.h>,' \
  515.     -e 's,"../machine/psl.h",<machine/psl.h>,' \
  516.   ${LIB}/$file > ${LIB}/${file}.sed
  517.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  518.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  519.     rm ${LIB}/$file
  520.   fi
  521. fi
  522.  
  523. # Fix an error in this file: the #if says _cplusplus, not the double
  524. # underscore __cplusplus that it should be
  525. file=tinfo.h
  526. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  527.   mkdir ${LIB}/rpcsvc 2>/dev/null
  528.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  529.   chmod +w ${LIB}/$file 2>/dev/null
  530.   chmod a+r ${LIB}/$file 2>/dev/null
  531. fi
  532.  
  533. if [ -r ${LIB}/$file ]; then
  534.   echo Fixing $file, __cplusplus macro
  535.   sed -e 's/[     ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
  536.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  537.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  538.     rm ${LIB}/$file
  539.   fi
  540. fi
  541.  
  542. # Fix an error in this file: a missing semi-colon at the end of the statsswtch
  543. # structure definition.
  544. file=rpcsvc/rstat.h
  545. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  546.   mkdir ${LIB}/rpcsvc 2>/dev/null
  547.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  548.   chmod +w ${LIB}/$file 2>/dev/null
  549.   chmod a+r ${LIB}/$file 2>/dev/null
  550. fi
  551.  
  552. if [ -r ${LIB}/$file ]; then
  553.   echo Fixing $file, definition of statsswtch
  554.   sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
  555.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  556.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  557.     rm ${LIB}/$file
  558.   fi
  559. fi
  560.  
  561. # Fix an error in this file: a missing semi-colon at the end of the nodeent
  562. # structure definition.
  563. file=netdnet/dnetdb.h
  564. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  565.   mkdir ${LIB}/netdnet 2>/dev/null
  566.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  567.   chmod +w ${LIB}/$file 2>/dev/null
  568.   chmod a+r ${LIB}/$file 2>/dev/null
  569. fi
  570.  
  571. if [ -r ${LIB}/$file ]; then
  572.   echo Fixing $file, definition of nodeent
  573.   sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
  574.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  575.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  576.     rm ${LIB}/$file
  577.   fi
  578. fi
  579.  
  580. # Check for bad #ifdef line (in Ultrix 4.1)
  581. file=sys/file.h
  582. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  583.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  584.   chmod +w ${LIB}/$file 2>/dev/null
  585.   chmod a+r ${LIB}/$file 2>/dev/null
  586. fi
  587.  
  588. if [ -r ${LIB}/$file ]; then
  589.   echo Fixing $file, bad \#ifdef line
  590.   sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
  591.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  592.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  593.     rm ${LIB}/$file
  594.   fi
  595. fi
  596.  
  597. # Check for superfluous `static' (in Ultrix 4.2)
  598. # On Ultrix 4.3, includes of other files (r3_cpu.h,r4_cpu.h) is broken.
  599. file=machine/cpu.h
  600. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  601.   mkdir ${LIB}/machine 2>/dev/null
  602.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  603.   chmod +w ${LIB}/$file 2>/dev/null
  604.   chmod a+r ${LIB}/$file 2>/dev/null
  605. fi
  606.  
  607. if [ -r ${LIB}/$file ]; then
  608.   echo Fixing $file, superfluous static and broken includes of other files.
  609.   sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' \
  610.       -e 's/^#include "r3_cpu\.h"$/#include <machine\/r3_cpu\.h>/' \
  611.       -e 's/^#include "r4_cpu\.h"$/#include <machine\/r4_cpu\.h>/' \
  612.       ${LIB}/$file > ${LIB}/${file}.sed
  613.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  614.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  615.     rm ${LIB}/$file
  616.   else
  617. # This file has an alternative name, mips/cpu.h.  Fix that name, too.
  618.     if cmp machine/cpu.h mips/cpu.h > /dev/null 2>&1; then
  619.       mkdir ${LIB}/mips 2>&-
  620. # Don't remove the file first, they may be the same file!
  621.       ln ${LIB}/$file ${LIB}/mips/cpu.h > /dev/null 2>&1
  622.     fi
  623.   fi
  624. fi
  625.  
  626. # Incorrect sprintf declaration in X11/Xmu.h
  627. file=X11/Xmu.h
  628. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  629.   mkdir ${LIB}/X11 2>/dev/null
  630.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  631.   chmod +w ${LIB}/$file 2>/dev/null
  632.   chmod a+r ${LIB}/$file 2>/dev/null
  633. fi
  634.  
  635. if [ -r ${LIB}/$file ]; then
  636.   echo Fixing $file sprintf declaration
  637.   sed -e 's,^extern char \*    sprintf();$,#ifndef __STDC__\
  638. extern char *    sprintf();\
  639. #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
  640.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  641.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  642.     rm ${LIB}/$file
  643.   fi
  644. fi
  645.  
  646. # Incorrect sprintf declaration in X11/Xmu/Xmu.h
  647. # (It's not clear whether the right file name is this or X11/Xmu.h.)
  648. file=X11/Xmu/Xmu.h
  649. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  650.   mkdir ${LIB}/X11/Xmu 2>/dev/null
  651.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  652.   chmod +w ${LIB}/$file 2>/dev/null
  653.   chmod a+r ${LIB}/$file 2>/dev/null
  654. fi
  655.  
  656. if [ -r ${LIB}/$file ]; then
  657.   echo Fixing $file sprintf declaration
  658.   sed -e 's,^extern char \*    sprintf();$,#ifndef __STDC__\
  659. extern char *    sprintf();\
  660. #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
  661.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  662.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  663.     rm ${LIB}/$file
  664.   fi
  665. fi
  666.  
  667. # Check for missing ';' in struct
  668. file=netinet/ip.h
  669. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  670.   mkdir ${LIB}/netinet 2>/dev/null
  671.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  672.   chmod +w ${LIB}/$file 2>/dev/null
  673.   chmod a+r ${LIB}/$file 2>/dev/null
  674. fi
  675.  
  676. if [ -r ${LIB}/$file ]; then
  677.   echo Fixing $file
  678.   sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
  679.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  680.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  681.     rm -f ${LIB}/$file
  682.   fi
  683. fi
  684.  
  685. # Fix the CAT macro in SunOS memvar.h.
  686. file=pixrect/memvar.h
  687. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  688.   mkdir ${LIB}/pixrect 2>/dev/null
  689.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  690.   chmod +w ${LIB}/$file 2>/dev/null
  691.   chmod a+r ${LIB}/$file 2>/dev/null
  692. fi
  693.  
  694. if [ -r ${LIB}/$file ]; then
  695.   echo Fixing $file
  696.   sed -e '/^#define.CAT(a,b)/ i\
  697. #ifdef __STDC__ \
  698. #define CAT(a,b) a##b\
  699. #else
  700. /^#define.CAT(a,b)/ a\
  701. #endif
  702. ' ${LIB}/$file > ${LIB}/${file}.sed
  703.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  704.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  705.     rm -f ${LIB}/$file
  706.   fi
  707. fi
  708.  
  709. # Check for yet more missing ';' in struct (in SunOS 4.0.x)
  710. file=rpcsvc/rusers.h
  711. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  712.   mkdir ${LIB}/rpcsvc 2>/dev/null
  713.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  714.   chmod +w ${LIB}/$file 2>/dev/null
  715.   chmod a+r ${LIB}/$file 2>/dev/null
  716. fi
  717.  
  718. if [ -r ${LIB}/$file ]; then
  719.   echo Fixing $file
  720.   sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
  721.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  722.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  723.     rm -f ${LIB}/$file
  724.   fi
  725. fi
  726.  
  727. # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
  728. # Also wrap protection around size_t for m88k-sysv3 systems.
  729. file=stdlib.h
  730. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  731.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  732.   chmod +w ${LIB}/$file 2>/dev/null
  733.   chmod a+r ${LIB}/$file 2>/dev/null
  734. fi
  735.  
  736. if [ -r ${LIB}/$file ]; then
  737.   echo Fixing $file
  738.   sed -e 's/int    abort/void    abort/g' \
  739.   -e 's/int    free/void    free/g' \
  740.   -e 's/char \*    calloc/void \*    calloc/g' \
  741.   -e 's/char \*    malloc/void \*    malloc/g' \
  742.   -e 's/char \*    realloc/void \*    realloc/g' \
  743.   -e 's/int    exit/void    exit/g' \
  744.   -e '/typedef[     a-zA-Z_]*[     ]size_t[     ]*;/i\
  745. #ifndef _GCC_SIZE_T\
  746. #define _GCC_SIZE_T
  747. ' \
  748.   -e '/typedef[     a-zA-Z_]*[     ]size_t[     ]*;/a\
  749. #endif
  750. ' \
  751.       ${LIB}/$file > ${LIB}/${file}.sed
  752.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  753.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  754.     rm -f ${LIB}/$file
  755.   fi
  756. fi
  757.  
  758. # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
  759. file=malloc.h
  760. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  761.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  762.   chmod +w ${LIB}/$file 2>/dev/null
  763.   chmod a+r ${LIB}/$file 2>/dev/null
  764. fi
  765.  
  766. if [ -r ${LIB}/$file ]; then
  767.   echo Fixing $file
  768.   sed -e 's/typedef[     ]char \*    malloc_t/typedef void \*    malloc_t/g' \
  769.   -e 's/int[     ][     ]*free/void    free/g' \
  770.   ${LIB}/$file > ${LIB}/${file}.sed
  771.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  772.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  773.     rm -f ${LIB}/$file
  774.   fi
  775. fi
  776.  
  777. # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
  778. file=hsfs/hsfs_spec.h
  779. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  780.   mkdir ${LIB}/hsfs 2>/dev/null
  781.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  782.   chmod +w ${LIB}/$file 2>/dev/null
  783.   chmod a+r ${LIB}/$file 2>/dev/null
  784. fi
  785.  
  786. if [ -r ${LIB}/$file ]; then
  787.   echo Fixing $file
  788.   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
  789.     ${LIB}/$file > ${LIB}/${file}.
  790.   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
  791.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  792.     rm -f ${LIB}/$file
  793.   fi
  794. fi
  795.  
  796. # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
  797. file=hsfs/hsnode.h
  798. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  799.   mkdir ${LIB}/hsfs 2>/dev/null
  800.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  801.   chmod +w ${LIB}/$file 2>/dev/null
  802.   chmod a+r ${LIB}/$file 2>/dev/null
  803. fi
  804.  
  805. if [ -r ${LIB}/$file ]; then
  806.   echo Fixing $file
  807.   sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
  808.     ${LIB}/$file > ${LIB}/${file}.sed
  809.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  810.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  811.     rm -f ${LIB}/$file
  812.   fi
  813. fi
  814.  
  815. # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
  816. file=hsfs/iso_spec.h
  817. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  818.   mkdir ${LIB}/hsfs 2>/dev/null
  819.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  820.   chmod +w ${LIB}/$file 2>/dev/null
  821.   chmod a+r ${LIB}/$file 2>/dev/null
  822. fi
  823.  
  824. if [ -r ${LIB}/$file ]; then
  825.   echo Fixing $file
  826.   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
  827.     ${LIB}/$file > ${LIB}/${file}.sed
  828.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  829.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  830.     rm -f ${LIB}/$file
  831.   fi
  832. fi
  833.  
  834. # Incorrect #include in Sony News-OS 3.2.
  835. file=machine/machparam.h
  836. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  837.   mkdir ${LIB}/machine 2>/dev/null
  838.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  839.   chmod +w ${LIB}/$file 2>/dev/null
  840.   chmod a+r ${LIB}/$file 2>/dev/null
  841. fi
  842.  
  843. if [ -r ${LIB}/$file ]; then
  844.   echo Fixing $file, incorrect \#include
  845.   sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
  846.     ${LIB}/$file > ${LIB}/${file}.
  847.   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
  848.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  849.     rm -f ${LIB}/$file
  850.   fi
  851. fi
  852.  
  853. # Multiline comment after typedef on IRIX 4.0.1.
  854. file=sys/types.h
  855. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  856.   mkdir ${LIB}/sys 2>/dev/null
  857.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  858.   chmod +w ${LIB}/$file 2>/dev/null
  859.   chmod a+r ${LIB}/$file 2>/dev/null
  860. fi
  861.  
  862. if [ -r ${LIB}/$file ]; then
  863.   echo Fixing $file, comment in the middle of \#ifdef
  864.   sed -e 's@type of the result@type of the result */@' \
  865.     -e 's@of the sizeof@/* of the sizeof@' \
  866.     ${LIB}/$file > ${LIB}/${file}.sed
  867.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  868.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  869.     rm -f ${LIB}/$file
  870.   fi
  871. fi
  872.  
  873. # Turning // comments into /* */ comments trashes this IRIX 4.0.1
  874. # header file, which embeds // comments inside multi-line /* */
  875. # comments.  If this looks like the IRIX header file, we refix it by
  876. # just throwing away the // comments.
  877. file=fam.h
  878. if [ -r ${LIB}/$file ]; then
  879.   if egrep indigo.esd ${LIB}/$file > /dev/null; then
  880.     echo Fixing $file, overeager sed script
  881.     rm ${LIB}/$file
  882.     sed -e 's|//.*$||g' $file > ${LIB}/$file
  883.     chmod +w ${LIB}/$file 2>/dev/null
  884.     chmod a+r ${LIB}/$file 2>/dev/null
  885.   fi
  886. fi
  887.  
  888. # Some IRIX header files contains the string "//"
  889. for file in elf_abi.h elf.h; do
  890.   if [ -r ${LIB}/$file ]; then
  891.     echo Fixing $file, overeager sed script
  892.     sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
  893.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  894.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  895.       rm -f ${LIB}/$file
  896.     fi
  897.   fi
  898. done
  899.  
  900. # IRIX 4.0.5 <rpc/auth.h> uses struct sockaddr in prototype without
  901. # previous definition.
  902. file=rpc/auth.h
  903. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  904.   mkdir ${LIB}/rpc 2>/dev/null
  905.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  906.   chmod +w ${LIB}/$file 2>/dev/null
  907.   chmod a+r ${LIB}/$file 2>/dev/null
  908. fi
  909.  
  910. if [ -r ${LIB}/$file ]; then
  911.   echo Fixing $file, undefined type
  912.   sed -e '/authdes_create.*struct sockaddr/i\
  913. struct sockaddr;
  914. ' \
  915.     ${LIB}/$file > ${LIB}/$file.sed
  916.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  917.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  918.     rm -f ${LIB}/$file
  919.   fi
  920. fi
  921.  
  922. # IRIX 4.0.5 <rpc/xdr.h> uses struct __file_s in prototype without previous
  923. # definition.
  924. file=rpc/xdr.h
  925. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  926.   mkdir ${LIB}/rpc 2>/dev/null
  927.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  928.   chmod +w ${LIB}/$file 2>/dev/null
  929.   chmod a+r ${LIB}/$file 2>/dev/null
  930. fi
  931.  
  932. if [ -r ${LIB}/$file ]; then
  933.   echo Fixing $file, undefined type
  934.   sed -e '/xdrstdio_create.*struct __file_s/i\
  935. struct __file_s;
  936. ' \
  937.     ${LIB}/$file > ${LIB}/$file.sed
  938.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  939.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  940.     rm -f ${LIB}/$file
  941.   fi
  942. fi
  943.  
  944. # Same problem with a file from SunOS 4.1.3 : a header file containing
  945. # the string "//" embedded in "/**/"
  946. file=sbusdev/audiovar.h
  947. if [ -r ${LIB}/$file ]; then
  948.   echo Fixing $file, overeager sed script
  949.   rm ${LIB}/$file
  950.   sed -e 's|//.*$||g' $file > ${LIB}/$file
  951.   chmod +w ${LIB}/$file 2>/dev/null
  952.   chmod a+r ${LIB}/$file 2>/dev/null
  953. fi
  954.  
  955. # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
  956. # declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
  957. # many other systems have similar text but correct versions of the file.
  958. # To ensure only Sun's is fixed, we grep for a likely unique string.
  959. file=memory.h
  960. if [ -r $file ] && egrep '/\*    @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2    \*/' $file > /dev/null; then
  961.   if [ ! -r ${LIB}/$file ]; then
  962.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  963.     chmod +w ${LIB}/$file 2>/dev/null
  964.     chmod a+r ${LIB}/$file 2>/dev/null
  965.   fi
  966.   if [ -r ${LIB}/$file ]; then
  967.     echo Replacing $file
  968.     cat > ${LIB}/$file << EOF
  969. /* This file was generated by fixincludes */
  970. #ifndef __memory_h__
  971. #define __memory_h__
  972.  
  973. #ifdef __STDC__
  974. extern void *memccpy();
  975. extern void *memchr();
  976. extern void *memcpy();
  977. extern void *memset();
  978. #else
  979. extern char *memccpy();
  980. extern char *memchr();
  981. extern char *memcpy();
  982. extern char *memset();
  983. #endif /* __STDC__ */
  984.  
  985. extern int memcmp();
  986.  
  987. #endif /* __memory_h__ */
  988. EOF
  989.   fi
  990. fi
  991.  
  992. # parameters not const on DECstation Ultrix V4.0.
  993. file=stdio.h
  994. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  995.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  996.   chmod +w ${LIB}/$file 2>/dev/null
  997.   chmod a+r ${LIB}/$file 2>/dev/null
  998. fi
  999.  
  1000. if [ -r ${LIB}/$file ]; then
  1001.   echo Fixing $file, non-const arg
  1002.   sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
  1003.       -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
  1004.       -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
  1005.       -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
  1006.       -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
  1007.       -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
  1008.       -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
  1009.     ${LIB}/$file > ${LIB}/${file}.sed
  1010.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1011.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1012.     rm -f ${LIB}/$file
  1013.   fi
  1014. fi
  1015.  
  1016. # parameters conflict with C++ new on rs/6000 
  1017. for file in stdio.h unistd.h ; do
  1018.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1019.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1020.     chmod +w ${LIB}/$file 2>/dev/null
  1021.   fi
  1022.  
  1023.   if [ -r ${LIB}/$file ]; then
  1024.     echo Fixing $file, parameter name conflicts
  1025.     sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
  1026.       ${LIB}/$file > ${LIB}/${file}.sed
  1027.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1028.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1029.       rm -f ${LIB}/$file
  1030.     fi
  1031.   fi
  1032. done
  1033.  
  1034. # function class(double x) conflicts with C++ keyword on rs/6000 
  1035. file=math.h
  1036. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1037.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1038.   chmod +w ${LIB}/$file 2>/dev/null
  1039.   chmod a+r ${LIB}/$file 2>/dev/null
  1040. fi
  1041.  
  1042. if [ -r ${LIB}/$file ]; then
  1043.   if grep 'class[(]' ${LIB}/$file >/dev/null; then
  1044.     echo Fixing $file
  1045.     sed -e '/class[(]/i\
  1046. #ifndef __cplusplus
  1047. ' \
  1048.         -e '/class[(]/a\
  1049. #endif
  1050. ' ${LIB}/$file > ${LIB}/${file}.sed
  1051.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1052.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1053.       rm ${LIB}/$file
  1054.     fi
  1055.   fi
  1056. fi
  1057.  
  1058. # Wrong fchmod prototype on RS/6000.
  1059. file=sys/stat.h
  1060. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1061.   mkdir ${LIB}/sys 2>/dev/null
  1062.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1063.   chmod +w ${LIB}/$file 2>/dev/null
  1064.   chmod a+r ${LIB}/$file 2>/dev/null
  1065. fi
  1066.  
  1067. if [ -r ${LIB}/$file ]; then
  1068.   echo Fixing $file, fchmod prototype
  1069.   sed -e 's/fchmod(char \*/fchmod(int/' \
  1070.     ${LIB}/$file > ${LIB}/$file.sed
  1071.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1072.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1073.     rm -f ${LIB}/$file
  1074.   fi
  1075. fi
  1076.  
  1077. # There are several name conflicts with C++ reserved words in X11
  1078. # header files.  These are fixed in some versions, so don't do the
  1079. # fixes if we find __cplusplus in the file.  These were found on the
  1080. # RS/6000.
  1081.  
  1082. # class in X11/ShellP.h
  1083. file=X11/ShellP.h
  1084. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1085.   mkdir ${LIB}/sys 2>/dev/null
  1086.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1087.   chmod +w ${LIB}/$file 2>/dev/null
  1088.   chmod a+r ${LIB}/$file 2>/dev/null
  1089. fi
  1090.  
  1091. if [ -r ${LIB}/$file ]; then
  1092.   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
  1093.     true;
  1094.   else
  1095.     echo Fixing $file, field class
  1096.     sed -e '/char [*]class;/i\
  1097. #ifdef __cplusplus\
  1098.     char *c_class;\
  1099. #else
  1100. ' \
  1101.         -e '/char [*]class;/a\
  1102. #endif
  1103. ' ${LIB}/$file > ${LIB}/${file}.sed
  1104.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1105.   fi
  1106.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1107.     rm -f ${LIB}/$file
  1108.   fi
  1109. fi
  1110. # new in Xm/Traversal.h
  1111. file=Xm/Traversal.h
  1112. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1113.   mkdir ${LIB}/sys 2>/dev/null
  1114.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1115.   chmod +w ${LIB}/$file 2>/dev/null
  1116.   chmod a+r ${LIB}/$file 2>/dev/null
  1117. fi
  1118.  
  1119. if [ -r ${LIB}/$file ]; then
  1120.   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
  1121.     true;
  1122.   else
  1123.     echo Fixing $file, uses of new
  1124.     sed -e '/Widget    old, new;/i\
  1125. #ifdef __cplusplus\
  1126.     Widget    old, c_new;\
  1127. #else
  1128. ' \
  1129.         -e '/Widget    old, new;/a\
  1130. #endif
  1131. ' \
  1132.     -e 's/Widget new,/Widget c_new,/g' ${LIB}/$file > ${LIB}/${file}.sed
  1133.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1134.   fi
  1135.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1136.     rm -f ${LIB}/$file
  1137.   fi
  1138. fi
  1139. # class in Xm/BaseClassI.h
  1140. file=Xm/BaseClassI.h
  1141. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1142.   mkdir ${LIB}/sys 2>/dev/null
  1143.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1144.   chmod +w ${LIB}/$file 2>/dev/null
  1145.   chmod a+r ${LIB}/$file 2>/dev/null
  1146. fi
  1147.  
  1148. if [ -r ${LIB}/$file ]; then
  1149.   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
  1150.     true;
  1151.   else
  1152.     echo Fixing $file, prototype parameter name
  1153.     sed -e 's/ class[)]/ c_class)/g' ${LIB}/$file > ${LIB}/${file}.sed
  1154.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1155.   fi
  1156.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1157.     rm -f ${LIB}/$file
  1158.   fi
  1159. fi
  1160.  
  1161.  
  1162. # NeXT 2.0 defines 'int wait(union wait*)', which conflicts with Posix.1.
  1163. # Note that version 3 of the NeXT system has wait.h in a different directory,
  1164. # so that this code won't do anything.  But wait.h in version 3 has a
  1165. # conditional, so it doesn't need this fix.  So everything is okay.
  1166. file=sys/wait.h
  1167. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1168.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1169.   chmod +w ${LIB}/$file 2>/dev/null
  1170. fi
  1171.  
  1172. if [ -r ${LIB}/$file ] \
  1173.   && grep 'wait[(]union wait' ${LIB}/$file >/dev/null; then
  1174.   echo Fixing $file, bad wait formal
  1175.   sed -e 's@wait(union wait@wait(void@' ${LIB}/$file > ${LIB}/${file}.sed
  1176.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1177.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1178.     rm -f ${LIB}/$file
  1179.   fi
  1180. fi
  1181.  
  1182. # Don't use or define the name va_list in stdio.h.
  1183. # This is for ANSI and also to interoperate properly with gcc's varargs.h.
  1184. file=stdio.h
  1185. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1186.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1187.   chmod +w ${LIB}/$file 2>/dev/null
  1188.   chmod a+r ${LIB}/$file 2>/dev/null
  1189. fi
  1190.  
  1191. if [ -r ${LIB}/$file ]; then
  1192.   echo Fixing $file, use of va_list
  1193.   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
  1194.   (echo "#define __need___va_list"
  1195.    echo "#include <stdarg.h>") > ${LIB}/${file}.sed
  1196.   # Use __gnuc_va_list in arg types in place of va_list.
  1197.   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
  1198.   # trailing parentheses and semicolon save all other systems from this.
  1199.   # Define __va_list__ (something harmless and unused) instead of va_list.
  1200.   # Don't claim to have defined va_list.
  1201.   sed -e 's@ va_list @ __gnuc_va_list @' \
  1202.       -e 's@ va_list)@ __gnuc_va_list)@' \
  1203.       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
  1204.       -e 's@ va_list@ __va_list__@' \
  1205.       -e 's@\*va_list@*__va_list__@' \
  1206.       -e 's@ __va_list)@ __gnuc_va_list)@' \
  1207.       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
  1208.       -e 's@VA_LIST@DUMMY_VA_LIST@' \
  1209.       -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \
  1210.     ${LIB}/$file >> ${LIB}/${file}.sed
  1211.   
  1212.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1213.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1214.     rm -f ${LIB}/$file
  1215.   fi
  1216. fi
  1217.  
  1218. # Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
  1219. file=ansi_compat.h
  1220. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1221.   if grep -s ULTRIX $file; then
  1222.     echo "/* This file intentionally left blank.  */" > $LIB/$file
  1223.   fi
  1224. fi
  1225.  
  1226. # parameter to atof not const on DECstation Ultrix V4.0.
  1227. # also get rid of bogus inline definitions in HP-UX 8.0
  1228. file=math.h
  1229. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1230.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1231.   chmod +w ${LIB}/$file 2>/dev/null
  1232.   chmod a+r ${LIB}/$file 2>/dev/null
  1233. fi
  1234.  
  1235. if [ -r ${LIB}/$file ]; then
  1236.   echo Fixing $file, non-const arg
  1237.   sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
  1238.       -e 's@inline int abs(int [a-z][a-z]*) {.*}@@' \
  1239.       -e 's@inline double abs(double [a-z][a-z]*) {.*}@@' \
  1240.       -e 's@inline int sqr(int [a-z][a-z]*) {.*}@@' \
  1241.       -e 's@inline double sqr(double [a-z][a-z]*) {.*}@@' \
  1242.     ${LIB}/$file > ${LIB}/${file}.sed
  1243.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1244.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1245.     rm -f ${LIB}/$file
  1246.   fi
  1247. fi
  1248.  
  1249. # Avoid nested comments on Ultrix 4.3.
  1250. file=rpc/svc.h
  1251. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1252.   mkdir ${LIB}/rpc 2>/dev/null
  1253.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1254.   chmod +w ${LIB}/$file 2>/dev/null
  1255.   chmod a+r ${LIB}/$file 2>/dev/null
  1256. fi
  1257.  
  1258. if [ -r ${LIB}/$file ]; then
  1259.   echo Fixing $file, nested comment
  1260.   sed -e 's@^\( \*    int protocol;  \)/\*@\1*/ /*@' \
  1261.     ${LIB}/$file > ${LIB}/$file.sed
  1262.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1263.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1264.     rm -f ${LIB}/$file
  1265.   fi
  1266. fi
  1267.  
  1268. # This file in RISC/os uses /**/ to concatenate two tokens.
  1269. file=bsd43/bsd43_.h
  1270. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1271.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1272.   chmod +w ${LIB}/$file 2>/dev/null
  1273.   chmod a+r ${LIB}/$file 2>/dev/null
  1274. fi
  1275. if [ -r ${LIB}/$file ]; then
  1276.   sed -e 's|/\*\*/|##|' ${LIB}/$file > ${LIB}/${file}.sed
  1277.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1278.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1279.     rm -f ${LIB}/$file
  1280.   fi
  1281. fi
  1282.  
  1283. file=rpc/rpc.h
  1284. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1285.   mkdir ${LIB}/rpc 2>/dev/null
  1286.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1287.   chmod +w ${LIB}/$file 2>/dev/null
  1288.   chmod a+r ${LIB}/$file 2>/dev/null
  1289. fi
  1290.  
  1291. if [ -r ${LIB}/$file ]; then
  1292.   echo Fixing $file, nested comment
  1293.   sed -e 's@^\(/\*.*rpc/auth_des.h>.*\)/\*@\1*/ /*@' \
  1294.     ${LIB}/$file > ${LIB}/$file.sed
  1295.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1296.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1297.     rm -f ${LIB}/$file
  1298.   fi
  1299. fi
  1300.  
  1301. # In limits.h, put #ifndefs around things that are supposed to be defined
  1302. # in float.h to avoid redefinition errors if float.h is included first.
  1303. # On HP/UX this patch does not work, because on HP/UX limits.h uses
  1304. # multi line comments and the inserted #endif winds up inside the
  1305. # comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
  1306. # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
  1307. # are there, and we do not add them ourselves.
  1308. for file in limits.h sys/limits.h; do
  1309.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1310.     mkdir ${LIB}/sys 2>/dev/null
  1311.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1312.     chmod +w ${LIB}/$file 2>/dev/null
  1313.     chmod a+r ${LIB}/$file 2>/dev/null
  1314.   fi
  1315.  
  1316.   if [ -r ${LIB}/$file ]; then
  1317.     if egrep 'ifndef[     ]+FLT_MIN' ${LIB}/$file >/dev/null; then
  1318.       true
  1319.     else
  1320.       echo Fixing $file
  1321.       sed -e '/[     ]FLT_MIN[     ]/i\
  1322. #ifndef FLT_MIN
  1323. '\
  1324.       -e '/[     ]FLT_MIN[     ]/a\
  1325. #endif
  1326. '\
  1327.       -e '/[     ]FLT_MAX[     ]/i\
  1328. #ifndef FLT_MAX
  1329. '\
  1330.       -e '/[     ]FLT_MAX[     ]/a\
  1331. #endif
  1332. '\
  1333.       -e '/[     ]FLT_DIG[     ]/i\
  1334. #ifndef FLT_DIG
  1335. '\
  1336.       -e '/[     ]FLT_DIG[     ]/a\
  1337. #endif
  1338. '\
  1339.       -e '/[     ]DBL_MIN[     ]/i\
  1340. #ifndef DBL_MIN
  1341. '\
  1342.       -e '/[     ]DBL_MIN[     ]/a\
  1343. #endif
  1344. '\
  1345.       -e '/[     ]DBL_MAX[     ]/i\
  1346. #ifndef DBL_MAX
  1347. '\
  1348.       -e '/[     ]DBL_MAX[     ]/a\
  1349. #endif
  1350. '\
  1351.       -e '/[     ]DBL_DIG[     ]/i\
  1352. #ifndef DBL_DIG
  1353. '\
  1354.       -e '/[     ]DBL_DIG[     ]/a\
  1355. #endif
  1356. '\
  1357.     ${LIB}/$file > ${LIB}/${file}.sed
  1358.       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1359.     fi
  1360.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1361.       echo Deleting ${LIB}/$file\; no fixes were needed.
  1362.       rm -f ${LIB}/$file
  1363.     fi
  1364.   fi
  1365. done
  1366.  
  1367. # In math.h, put #ifndefs around things that might be defined in a gcc
  1368. # specific math-*.h file.
  1369. file=math.h
  1370. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1371.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1372.   chmod +w ${LIB}/$file 2>/dev/null
  1373.   chmod a+r ${LIB}/$file 2>/dev/null
  1374. fi
  1375.  
  1376. if [ -r ${LIB}/$file ]; then
  1377.   echo Fixing $file
  1378.   sed -e '/define[     ]HUGE_VAL[     ]/i\
  1379. #ifndef HUGE_VAL
  1380. '\
  1381.       -e '/define[     ]HUGE_VAL[     ]/a\
  1382. #endif
  1383. '\
  1384.     ${LIB}/$file > ${LIB}/${file}.sed
  1385.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1386.  
  1387.   # In addition, copy the definition of DBL_MAX from float.h
  1388.   # if math.h requires one.  The Lynx math.h requires it.
  1389.   if egrep '#define[     ]*HUGE_VAL[     ]+DBL_MAX' $file >/dev/null 2>&1; then
  1390.     if egrep '#define[     ]+DBL_MAX[     ]+' $file >/dev/null 2>&1; then
  1391.       true;
  1392.     else
  1393.       dbl_max_def=`egrep 'define[     ]+DBL_MAX[     ]+.*' float.h 2>/dev/null`
  1394.       if [ "$dbl_max_def" != "" ]; then
  1395.         dbl_max_def=`echo $dbl_max_def | sed 's/.*define[     ]*DBL_MAX[     ]*//'`
  1396.         sed -e "/define[     ]HUGE_VAL[     ]DBL_MAX/s/DBL_MAX/$dbl_max_def/" \
  1397.           ${LIB}/$file > ${LIB}/${file}.sed
  1398.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1399.       fi
  1400.     fi
  1401.   fi
  1402.  
  1403.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1404.     echo Deleting ${LIB}/$file\; no fixes were needed.
  1405.     rm -f ${LIB}/$file
  1406.   fi
  1407. fi
  1408.  
  1409. # Remove erroneous parentheses in sym.h on Alpha OSF/1.
  1410. file=sym.h
  1411. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1412.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1413.   chmod +w ${LIB}/$file 2>/dev/null
  1414.   chmod a+r ${LIB}/$file 2>/dev/null
  1415. fi
  1416.  
  1417. if [ -r ${LIB}/$file ]; then
  1418.   echo Fixing $file
  1419.   sed -e 's/#ifndef(__mips64)/#ifndef __mips64/' \
  1420.     ${LIB}/$file > ${LIB}/${file}.sed
  1421.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1422.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1423.     rm -f ${LIB}/$file
  1424.   fi
  1425. fi
  1426.  
  1427. # Correct the return type for strlen in string.h on Lynx.
  1428. # Correct the argument type for ffs in string.h on Alpha OSF/1 V2.0.
  1429. file=string.h
  1430. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1431.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1432.   chmod +w ${LIB}/$file 2>/dev/null
  1433.   chmod a+r ${LIB}/$file 2>/dev/null
  1434. fi
  1435.  
  1436. if [ -r ${LIB}/$file ]; then
  1437.   echo Fixing $file
  1438.   sed -e 's/extern[     ]*int[     ]*strlen();/extern unsigned int strlen();/' \
  1439.       -e 's/extern[     ]*int[     ]*ffs[     ]*(long);/extern int ffs(int);/' \
  1440.     ${LIB}/$file > ${LIB}/${file}.sed
  1441.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1442.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1443.     rm -f ${LIB}/$file
  1444.   fi
  1445. fi
  1446.  
  1447. # Delete the '#define void int' line from curses.h on Lynx
  1448. file=curses.h
  1449. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1450.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1451.   chmod +w ${LIB}/$file 2>/dev/null
  1452.   chmod a+r ${LIB}/$file 2>/dev/null
  1453. fi
  1454.  
  1455. if [ -r ${LIB}/$file ]; then
  1456.   echo Fixing $file
  1457.   sed -e '/#define[     ][     ]*void[     ]int/d' \
  1458.      ${LIB}/$file > ${LIB}/${file}.sed
  1459.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1460.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1461.       rm -f ${LIB}/$file
  1462.   fi
  1463. fi
  1464.  
  1465. # For C++, avoid any typedef or macro definition of bool, and use the
  1466. # built in type instead.
  1467. for files in curses.h; do
  1468.   if [ -r $file ] && egrep bool $file >/dev/null 2>&1; then
  1469.     if [ ! -r ${LIB}/$file ]; then
  1470.       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1471.       chmod +w ${LIB}/$file 2>/dev/null
  1472.       chmod a+r ${LIB}/$file 2>/dev/null
  1473.     fi
  1474.  
  1475.     echo Fixing $file
  1476.     sed -e '/^#[     ]*define[     ][     ]*bool[     ][     ]*char[     ]*$/i\
  1477. #ifndef __cplusplus'\
  1478.     -e '/^#[     ]*define[     ][     ]*bool[     ][     ]*char[     ]*$/a\
  1479. #endif'\
  1480.     -e '/^typedef[     ][     ]*char[     ][     ]*bool;[     ]*$/i\
  1481. #ifndef __cplusplus'\
  1482.     -e '/^typedef[     ][     ]*char[     ][     ]*bool;[     ]*$/a\
  1483. #endif'\
  1484.     ${LIB}/$file > ${LIB}/${file}.sed
  1485.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1486.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1487.       rm -f ${LIB}/$file
  1488.     fi
  1489.   fi
  1490. done
  1491.  
  1492. # Fix incorrect S_IF* definitions on m88k-sysv3.
  1493. file=sys/stat.h
  1494. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1495.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1496.   chmod +w ${LIB}/$file 2>/dev/null
  1497.   chmod a+r ${LIB}/$file 2>/dev/null
  1498. fi
  1499.  
  1500. if [ -r ${LIB}/$file ]; then
  1501.   echo Fixing $file
  1502.   sed -e 's/^\(#define[     ]*S_IS[A-Z]*(m)\)[     ]*(m[     ]*&[     ]*\(S_IF[A-Z][A-Z][A-Z][A-Z]*\)[     ]*)/\1 (((m)\&S_IFMT)==\2)/' \
  1503.       -e 's/^\(#define[     ]*S_IS[A-Z]*(m)\)[     ]*(m[     ]*&[     ]*\(0[0-9]*\)[     ]*)/\1 (((m)\&S_IFMT)==\2)/' \
  1504.     ${LIB}/$file > ${LIB}/${file}.sed
  1505.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1506.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1507.     rm -f ${LIB}/$file
  1508.   fi
  1509. fi
  1510.  
  1511. # Fix getopt declarations in stdio.h and stdlib.h on Alpha OSF/1 and AIX.
  1512. for file in stdio.h stdlib.h; do
  1513.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1514.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1515.     chmod +w ${LIB}/$file 2>/dev/null
  1516.     chmod a+r ${LIB}/$file 2>/dev/null
  1517.   fi
  1518.  
  1519.   if [ -r ${LIB}/$file ]; then
  1520.     echo Fixing $file, getopt declaration
  1521.     sed -e 's/getopt(int, char \*\[\],[ ]*char \*)/getopt(int, char *const[], const char *)/' \
  1522.       ${LIB}/$file > ${LIB}/${file}.sed
  1523.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1524.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1525.       rm -f ${LIB}/$file
  1526.     fi
  1527.   fi
  1528. done
  1529.  
  1530. # Determine if we're on Interactive Unix 2.2 or later, in which case we
  1531. # need to fix some additional files.  This is the same test for ISC that
  1532. # Autoconf uses.
  1533. if test -d /etc/conf/kconfig.d \
  1534.     && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
  1535.   echo "Fixing ISC __STDC__ goof in several files..."
  1536.   for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
  1537.     echo $name
  1538.     if test -r ${LIB}/$name; then
  1539.       file=${LIB}/$name
  1540.     else
  1541.       file=${INPUT}/$name
  1542.     fi
  1543.     # On Interactive 2.2, certain traditional Unix definitions
  1544.     # (notably getc and putc in stdio.h) are omitted if __STDC__ is
  1545.     # defined, not just if _POSIX_SOURCE is defined.  This makes it
  1546.     # impossible to compile any nontrivial program except with -posix.
  1547.     sed \
  1548. 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
  1549.         < $file > ${LIB}/$name.
  1550.     mv ${LIB}/$name. ${LIB}/$name
  1551.   done
  1552.   
  1553.   echo "Fixing ISC fmod declaration"
  1554.   # This one's already been fixed for other things.
  1555.   file=${LIB}/math.h
  1556.   sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
  1557.   mv $file. $file
  1558.   
  1559.   echo "Fixing nested comments in ISC <sys/limits.h>"
  1560.   file=sys/limits.h
  1561.   sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
  1562.   sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
  1563. fi
  1564.  
  1565. # These files in Sun OS 4.x use /**/ to concatenate tokens.
  1566. for file in sparc/asm_linkage.h sun3/asm_linkage.h sun3x/asm_linkage.h    \
  1567.     sun4/asm_linkage.h sun4c/asm_linkage.h sun4m/asm_linkage.h    \
  1568.     sun4c/debug/asm_linkage.h sun4m/debug/asm_linkage.h;
  1569. do
  1570.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1571.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1572.     chmod +w ${LIB}/$file 2>/dev/null
  1573.     chmod a+r ${LIB}/$file 2>/dev/null
  1574.   fi
  1575.  
  1576.   if [ -r ${LIB}/$file ]; then
  1577.     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
  1578.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1579.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1580.       rm -f ${LIB}/$file
  1581.     fi
  1582.   fi
  1583. done
  1584.  
  1585. # These files in ARM/RISCiX use /**/ to concatenate tokens.
  1586. for file in arm/as_support.h arm/mc_type.h arm/xcb.h dev/chardefmac.h \
  1587.     dev/ps_irq.h dev/screen.h dev/scsi.h sys/tty.h Xm.acorn/XmP.h
  1588. do
  1589.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1590.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1591.     chmod +w ${LIB}/$file 2>/dev/null
  1592.     chmod a+r ${LIB}/$file 2>/dev/null
  1593.   fi
  1594.  
  1595.   if [ -r ${LIB}/$file ]; then
  1596.     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
  1597.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1598.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1599.       rm -f ${LIB}/$file
  1600.     fi
  1601.   fi
  1602. done
  1603.  
  1604. # math.h on SunOS 4 puts the declaration of matherr before the definition
  1605. # of struct exception, so the prototype (added by fixproto) causes havoc.
  1606. file=math.h
  1607. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1608.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1609.   chmod +w ${LIB}/$file 2>/dev/null
  1610.   chmod a+r ${LIB}/$file 2>/dev/null
  1611. fi
  1612.  
  1613. if [ -r ${LIB}/$file ]; then
  1614.   echo Fixing $file, matherr declaration
  1615.   sed -e '/^struct exception/,$b' \
  1616.       -e '/matherr/i\
  1617. struct exception;
  1618. '\
  1619.     ${LIB}/$file > ${LIB}/${file}.sed
  1620.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1621.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1622.     rm -f ${LIB}/$file
  1623.   fi
  1624. fi
  1625.  
  1626. # assert.h on HP/UX is not C++ ready, even though NO_IMPLICIT_EXTERN_C
  1627. # is defined on HP/UX.
  1628. file=assert.h
  1629. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1630.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1631.   chmod +w ${LIB}/$file 2>/dev/null
  1632.   chmod a+r ${LIB}/$file 2>/dev/null
  1633. fi
  1634.  
  1635. if [ -r ${LIB}/$file ]; then
  1636.   if egrep '"C"' ${LIB}/$file >/dev/null 2>/dev/null; then
  1637.     true
  1638.   else
  1639.     echo Fixing $file
  1640.     echo '#ifdef __cplusplus
  1641. extern "C" {
  1642. #endif' > ${LIB}/${file}.sed
  1643.     cat ${LIB}/${file} >> ${LIB}/${file}.sed
  1644.     echo '#ifdef __cplusplus
  1645. }
  1646. #endif' >> ${LIB}/${file}.sed 
  1647.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1648.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1649.       rm -f ${LIB}/$file
  1650.     fi
  1651.   fi
  1652. fi
  1653.  
  1654. # check for broken assert.h that needs stdio.h or stdlib.h
  1655. file=assert.h
  1656. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1657.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1658.   chmod +w ${LIB}/$file 2>/dev/null
  1659.   chmod a+r ${LIB}/$file 2>/dev/null
  1660. fi
  1661.  
  1662. if [ -r ${LIB}/$file ]; then
  1663.   if grep 'stderr' ${LIB}/$file >/dev/null 2>/dev/null; then
  1664.     if grep 'include.*stdio.h' ${LIB}/$file >/dev/null 2>/dev/null; then
  1665.       true
  1666.     else
  1667.       echo "Fixing $file (needs stdio.h)"
  1668.       echo '#include <stdio.h>' >>${LIB}/$file
  1669.     fi
  1670.   fi
  1671.   if grep 'exit *(' ${LIB}/$file >/dev/null 2>/dev/null || 
  1672.      grep 'abort *(' ${LIB}/$file >/dev/null 2>/dev/null; then
  1673.     if grep 'include.*stdlib.h' ${LIB}/$file >/dev/null 2>/dev/null; then
  1674.       true
  1675.     else
  1676.       echo "Fixing $file (needs stdlib.h)"
  1677.       echo '#include <stdlib.h>' >>${LIB}/$file
  1678.     fi
  1679.   fi
  1680.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1681.     rm -f ${LIB}/$file
  1682.   fi
  1683. fi
  1684.  
  1685. # Fix return value of sbrk in unistd.h on Alpha OSF/1 V2.0
  1686. file=unistd.h
  1687. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1688.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1689.   chmod +w ${LIB}/$file 2>/dev/null
  1690.   chmod a+r ${LIB}/$file 2>/dev/null
  1691. fi
  1692.  
  1693. if [ -r ${LIB}/$file ]; then
  1694.   echo Fixing $file, sbrk declaration
  1695.   sed -e 's/char\([     ]*\*[     ]*sbrk[     ]*(\)/void\1/' \
  1696.     ${LIB}/$file > ${LIB}/${file}.sed
  1697.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1698.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1699.     rm -f ${LIB}/$file
  1700.   fi
  1701. fi
  1702.  
  1703. # This file on SunOS 4 has a very large macro.  When the sed loop
  1704. # tries pull it in, it overflows the pattern space size of the SunOS
  1705. # sed (GNU sed does not have this problem).  Since the file does not
  1706. # require fixing, we remove it from the fixed directory.
  1707. file=sundev/ipi_error.h
  1708. if [ -r ${LIB}/$file ]; then
  1709.   echo "Removing incorrect fix to SunOS <sundev/ipi_error.h>"
  1710.   rm -f ${LIB}/$file
  1711. fi
  1712.  
  1713. # Put cpp wrappers around these include files to avoid redeclaration
  1714. # errors during multiple inclusion on m88k-tektronix-sysv3.
  1715. for file in time.h sys/time.h ; do
  1716.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1717.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1718.     chmod +w ${LIB}/$file 2>/dev/null
  1719.   fi
  1720.   if [ -r ${LIB}/$file ]; then
  1721.     echo Fixing $file, to protect against multiple inclusion.
  1722.     cpp_wrapper=`echo $file | sed -e 's,\.,_,g' -e 's,/,_,g'`
  1723.     (echo "#ifndef __GCC_GOT_${cpp_wrapper}_"
  1724.     echo "#define __GCC_GOT_${cpp_wrapper}_"
  1725.     cat ${LIB}/${file}
  1726.     echo '#endif /* !_GCC_GOT_'${cpp_wrapper}_' */')  > ${LIB}/${file}.new
  1727.     rm -f ${LIB}/$file; mv ${LIB}/${file}.new ${LIB}/$file
  1728.   fi
  1729. done
  1730.  
  1731. echo 'Removing unneeded directories:'
  1732. cd $LIB
  1733. files=`find . -type d -print | sort -r`
  1734. for file in $files; do
  1735.   rmdir $LIB/$file > /dev/null 2>&1
  1736. done
  1737.  
  1738. if $LINKS; then
  1739.   echo 'Making internal symbolic non-directory links'
  1740.   cd ${INPUT}
  1741.   files=`find . -type l -print`
  1742.   for file in $files; do
  1743.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  1744.     if expr "$dest" : '[^/].*' > /dev/null; then    
  1745.       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
  1746.       if [ -f $target ]; then
  1747.         ln -s $dest ${LIB}/$file >/dev/null 2>&1
  1748.       fi
  1749.     fi
  1750.   done
  1751. fi
  1752.  
  1753. # Make sure that any include files referenced using double quotes
  1754. # exist in the fixed directory.  This comes last since otherwise
  1755. # we might end up deleting some of these files "because they don't
  1756. # need any change."
  1757. while [ -n "$required" ]; do
  1758.   newreq=
  1759.   set x $required
  1760.   shift
  1761.   while [ $# != 0 ]; do
  1762.     # $1 is the directory to copy from, $2 is the unfixed file,
  1763.     # $3 is the fixed file name.
  1764.     cd ${INPUT}
  1765.     cd $1
  1766.     if [ -r $2 ] && [ ! -r $3 ]; then
  1767.       cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2"
  1768.       chmod +w $3 2>/dev/null
  1769.       chmod a+r $3 2>/dev/null
  1770.       echo Copied $2
  1771.       for include in `egrep '^[     ]*#[     ]*include[     ]*"[^/]' $3 | sed -e 's/^[     ]*#[     ]*include[     ]*"\([^"]*\)".*$/\1/'`; do
  1772.     dir=`echo $2 | sed -e s'|/[^/]*$||'`
  1773.     dir2=`echo $3 | sed -e s'|/[^/]*$||'`
  1774.     newreq="$newreq $1 $dir/$include $dir2/$include"
  1775.       done
  1776.     fi
  1777.     shift; shift; shift
  1778.   done
  1779.   required=$newreq
  1780. done
  1781.  
  1782. echo 'Cleaning up DONE files.'
  1783. cd $LIB
  1784. find . -name DONE -exec rm -f '{}' ';'
  1785.  
  1786. exit 0
  1787.